package com.epb.eventpcb.service.impl;

import com.epb.eventpcb.mapper.SysUserMapper;
import com.epb.eventpcb.pojo.SysUser;
import com.epb.eventpcb.pojo.SysUserExample;
import com.epb.eventpcb.service.ISysUserService;
import com.google.code.kaptcha.Producer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class SysUserServiceImpl implements ISysUserService {
    @Autowired
    SysUserMapper userMapper;

    @Resource()
    private Producer producer;

    @Override
    public List<SysUser> getUserByUsername(String username) {
        SysUserExample example = new SysUserExample();
        example.createCriteria().andUserNameEqualTo(username);
        return userMapper.selectByExample(example);
    }


    @Cacheable(cacheNames = "loginCode", key = "'loginCode_' + #key",
            cacheManager = "caffeineCodeCacheManager")
    public String getLoginCode(String key){
        String code = producer.createText();
        log.info("生成的code:{}",code);
        return code;
    }
}
